<!--多选-->
<template>
  <div class="multiple_box">
    <el-button :type="types" :size="size" plain @click="toggleCkList">
      {{ text }}<i class="el-icon-arrow-down el-icon--right"></i>
    </el-button>
    <div
      class="ck_box"
      tabindex="-1"
      :class="{ collapse: !isExpand }"
      @blur="hideCkList"
      ref="ckList"
    >
      <div class="ck_list">
        <el-checkbox-group v-model="checkList" @change="selectChange">
          <el-checkbox
            v-for="(item, index) in ckList"
            :key="index"
            :label="item.name"
          ></el-checkbox>
        </el-checkbox-group>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  props: {
    ckList: {
      type: Array,
      default: () => []
    },
    size: {
      type: String,
      default: 'small'
    },
    types: {
      type: String,
      default: 'primary'
    },
    text: {
      type: String,
      default: 'test'
    }
  },
  data () {
    return {
      checkList: [],
      isExpand: false,
    }
  },
  methods: {
    toggleCkList () {
      this.isExpand = true;
      this.$nextTick(() => {
        this.$refs.ckList.focus();
      });
    },
    hideCkList () {
      this.isExpand = false
    },
    selectChange (e) {
      this.isExpand = true;
      this.$nextTick(() => {
        this.$refs.ckList.focus();
      });
      this.emit('input', e)
    }
  },
  mounted () {

  }
}
</script>
<style lang="scss" scoped>
.multiple_box {
  display: inline-block;
  position: relative;
  .ck_box {
    position: absolute;
    right: 0;
    z-index: 99;
    top: 30px;
    padding-top: 11px;
    transition: height 300ms ease-in;
    &.collapse {
      display: none;
    }
  }
  .ck_list {
    background-color: #fff;
    border-radius: 4px;
    border: solid 1px #dfe4ed;
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
    padding: 8px 0;
    position: relative;

    &::after {
      content: '';
      position: absolute;
      border-left: 6px solid transparent;
      border-top: 6px solid transparent;
      border-bottom: 6px solid #e2e2e2;
      border-right: 6px solid transparent;
      top: -13px;
      right: 15px;
    }
    &::before {
      content: '';
      position: absolute;
      border-left: 6px solid transparent;
      border-top: 6px solid transparent;
      border-bottom: 6px solid #fff;
      border-right: 6px solid transparent;
      top: -12px;
      right: 15px;
      z-index: 9;
    }
    .el-checkbox-group {
      .el-checkbox {
        line-height: 28px;
        display: block;
        padding: 0 16px;
        margin: 0;
        min-width: 100px;
        &:hover {
          background-color: #f5f7fa;
        }
      }
    }
  }
}
</style>
